package com.ph.irp.base.verifyproject.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialCandiatecategoryDao;
import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialCultureDAO;
import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialDutyDao;
import com.ph.irp.base.verifyproject.dao.PBaseVerifyprojectCandiateDao;
import com.ph.irp.base.verifyproject.dao.PBaseVerifyprojectDepartmentDao;
import com.ph.irp.base.verifyproject.service.PBaseVerifyprojectCandiateService;
import com.ph.irp.dto.CandiateDTO;
import com.ph.irp.model.PBaseAssistantmaterialCandiatecategory;
import com.ph.irp.model.PBaseAssistantmaterialCulture;
import com.ph.irp.model.PBaseAssistantmaterialDuty;
import com.ph.irp.model.PBaseVerifyprojectCandiate;
import com.ph.irp.model.PBaseVerifyprojectDepartment;

public class PBaseVerifyprojectCandiateServiceImpl implements
		PBaseVerifyprojectCandiateService {
	private PBaseVerifyprojectCandiateDao candiateDaoProxy;
	private PBaseVerifyprojectDepartmentDao departmentDaoProxy;
	private PBaseAssistantmaterialCultureDAO cultureDaoProxy;
	private PBaseAssistantmaterialDutyDao dutyDaoProxy;
	private PBaseAssistantmaterialCandiatecategoryDao candiateCategoryDaoProxy;
	

	@Override
	public void addCandiate(PBaseVerifyprojectCandiate candiate) throws Throwable {
//			if(candiateDaoProxy.isSame(candiate.getCandiateCode())){
//				throw new Throwable("代码【"+candiate.getCandiateCode()+"】已经存在");
//			}else{
					candiateDaoProxy.addCandiate(candiate);
//			}
	}

	@Override
	public void deleteCandiate(int candiateId) throws Throwable {
			candiateDaoProxy.deleteCandiate(candiateId);

	}

	@Override
	public CandiateDTO getCandiateById(int candiateId) throws Throwable {
			CandiateDTO c = new CandiateDTO();
			PBaseVerifyprojectCandiate candiate = candiateDaoProxy.getCandiateById(candiateId);
			
			int PBaseVerifyprojectDepartmentId = candiate.getPBaseVerifyprojectDepartmentId();
			int PBaseAssistantmaterialDutyId = candiate.getPBaseAssistantmaterialDutyId();
			int PBaseAssistantmaterialCultureId = candiate.getPBaseAssistantmaterialCultureId();
			int PBaseAssistantmaterialCandiatecategoryId = candiate.getPBaseAssistantmaterialCandiatecategoryId();
			int allowanceId = candiate.getAllowance();
			c.setCandiate(candiate);
			if(PBaseVerifyprojectDepartmentId != 0){
				PBaseVerifyprojectDepartment department = departmentDaoProxy.getDepartmentById(PBaseVerifyprojectDepartmentId);
				c.setDepartment(department);
			}
			if(PBaseAssistantmaterialDutyId != 0){
				PBaseAssistantmaterialDuty duty = dutyDaoProxy.getDutyById(PBaseAssistantmaterialDutyId);
				c.setDuty(duty);
			}
			if(PBaseAssistantmaterialCultureId != 0){
				PBaseAssistantmaterialCulture culture = cultureDaoProxy.getAssistantmaterialCultureById(PBaseAssistantmaterialCultureId);
				c.setCulture(culture);
			}
			if(PBaseAssistantmaterialCandiatecategoryId != 0){
				PBaseAssistantmaterialCandiatecategory candiateCategory = candiateCategoryDaoProxy.getCandiateCategoryById(PBaseAssistantmaterialCandiatecategoryId);
				c.setCandiateCategory(candiateCategory);
			}
			if(allowanceId != 0){
				PBaseVerifyprojectCandiate allowance = candiateDaoProxy.getCandiateById(candiate.getAllowance());
				//System.out.println("service:======================"+allowance.getCandiateName());
				c.setAllowance(allowance);
			}
			return c;
	}

	@Override
	public List<CandiateDTO> getCandiateList(PBaseVerifyprojectCandiate p) throws Throwable {
		List<CandiateDTO> candiates = new ArrayList<CandiateDTO>();
			List<PBaseVerifyprojectCandiate> list = candiateDaoProxy.getCandiateList(p);
			for(PBaseVerifyprojectCandiate pbvc : list){
				CandiateDTO c = new CandiateDTO();
				int PBaseVerifyprojectDepartmentId = pbvc.getPBaseVerifyprojectDepartmentId();
				int PBaseAssistantmaterialDutyId = pbvc.getPBaseAssistantmaterialDutyId();
				int PBaseAssistantmaterialCultureId = pbvc.getPBaseAssistantmaterialCultureId();
				int PBaseAssistantmaterialCandiatecategoryId = pbvc.getPBaseAssistantmaterialCandiatecategoryId();
				int allowanceId = pbvc.getAllowance();
				c.setCandiate(pbvc);
				if(PBaseVerifyprojectDepartmentId != 0){
					PBaseVerifyprojectDepartment department = departmentDaoProxy.getDepartmentById(PBaseVerifyprojectDepartmentId);
					c.setDepartment(department);
				}
				if(PBaseAssistantmaterialDutyId != 0){
					PBaseAssistantmaterialDuty duty = dutyDaoProxy.getDutyById(PBaseAssistantmaterialDutyId);
					c.setDuty(duty);
				}
				if(PBaseAssistantmaterialCultureId != 0){
					PBaseAssistantmaterialCulture culture = cultureDaoProxy.getAssistantmaterialCultureById(PBaseAssistantmaterialCultureId);
					c.setCulture(culture);
				}
				if(PBaseAssistantmaterialCandiatecategoryId != 0){
					PBaseAssistantmaterialCandiatecategory candiateCategory = candiateCategoryDaoProxy.getCandiateCategoryById(PBaseAssistantmaterialCandiatecategoryId);
					c.setCandiateCategory(candiateCategory);
				}
				if(allowanceId != 0){
					PBaseVerifyprojectCandiate allowance = candiateDaoProxy.getCandiateById(allowanceId);
					c.setAllowance(allowance);
				}
				candiates.add(c);
			}
		return candiates;
	}

	@Override
	public void updateCandiate(PBaseVerifyprojectCandiate candiate) throws Throwable {
		//PBaseVerifyprojectCandiate pbvc;
//			pbvc = candiateDaoProxy.getCandiateById(candiate.getCandiateId());
//			if(candiate.getCandiateCode().equals(pbvc.getCandiateCode())){
//				candiateDaoProxy.updateCandiate(candiate);
//			}else{
//				if(candiateDaoProxy.isSame(candiate.getCandiateCode())){
//					throw new Throwable("代码【"+candiate.getCandiateCode()+"】已经存在");
//				}else{
					candiateDaoProxy.updateCandiate(candiate);
//				}
//			}
	}

	public PBaseVerifyprojectCandiateDao getCandiateDaoProxy() {
		return candiateDaoProxy;
	}

	public void setCandiateDaoProxy(PBaseVerifyprojectCandiateDao candiateDaoProxy) {
		this.candiateDaoProxy = candiateDaoProxy;
	}

	public PBaseVerifyprojectDepartmentDao getDepartmentDaoProxy() {
		return departmentDaoProxy;
	}

	public void setDepartmentDaoProxy(
			PBaseVerifyprojectDepartmentDao departmentDaoProxy) {
		this.departmentDaoProxy = departmentDaoProxy;
	}

	public PBaseAssistantmaterialCultureDAO getCultureDaoProxy() {
		return cultureDaoProxy;
	}

	public void setCultureDaoProxy(PBaseAssistantmaterialCultureDAO cultureDaoProxy) {
		this.cultureDaoProxy = cultureDaoProxy;
	}

	public PBaseAssistantmaterialDutyDao getDutyDaoProxy() {
		return dutyDaoProxy;
	}

	public void setDutyDaoProxy(PBaseAssistantmaterialDutyDao dutyDaoProxy) {
		this.dutyDaoProxy = dutyDaoProxy;
	}

	public PBaseAssistantmaterialCandiatecategoryDao getCandiateCategoryDaoProxy() {
		return candiateCategoryDaoProxy;
	}

	public void setCandiateCategoryDaoProxy(
			PBaseAssistantmaterialCandiatecategoryDao candiateCategoryDaoProxy) {
		this.candiateCategoryDaoProxy = candiateCategoryDaoProxy;
	}

	@Override
	public List<CandiateDTO> getCandiateByCode(String code) throws Throwable {
		List<CandiateDTO> candiates = new ArrayList<CandiateDTO>();
		List<PBaseVerifyprojectCandiate> list = candiateDaoProxy.getCandiateByCode(code);
		for(PBaseVerifyprojectCandiate pbvc : list){
			CandiateDTO c = new CandiateDTO();
			int PBaseVerifyprojectDepartmentId = pbvc.getPBaseVerifyprojectDepartmentId();
			int PBaseAssistantmaterialDutyId = pbvc.getPBaseAssistantmaterialDutyId();
			int PBaseAssistantmaterialCultureId = pbvc.getPBaseAssistantmaterialCultureId();
			int PBaseAssistantmaterialCandiatecategoryId = pbvc.getPBaseAssistantmaterialCandiatecategoryId();
			int allowanceId = pbvc.getAllowance();
			c.setCandiate(pbvc);
			if(PBaseVerifyprojectDepartmentId != 0){
				PBaseVerifyprojectDepartment department = departmentDaoProxy.getDepartmentById(PBaseVerifyprojectDepartmentId);
				c.setDepartment(department);
			}
			if(PBaseAssistantmaterialDutyId != 0){
				PBaseAssistantmaterialDuty duty = dutyDaoProxy.getDutyById(PBaseAssistantmaterialDutyId);
				c.setDuty(duty);
			}
			if(PBaseAssistantmaterialCultureId != 0){
				PBaseAssistantmaterialCulture culture = cultureDaoProxy.getAssistantmaterialCultureById(PBaseAssistantmaterialCultureId);
				c.setCulture(culture);
			}
			if(PBaseAssistantmaterialCandiatecategoryId != 0){
				PBaseAssistantmaterialCandiatecategory candiateCategory = candiateCategoryDaoProxy.getCandiateCategoryById(PBaseAssistantmaterialCandiatecategoryId);
				c.setCandiateCategory(candiateCategory);
			}
			if(allowanceId != 0){
				PBaseVerifyprojectCandiate allowance = candiateDaoProxy.getCandiateById(allowanceId);
				c.setAllowance(allowance);
			}
			candiates.add(c);
		}
	return candiates;
	}

	@Override
	public List<CandiateDTO> getCandiateByCodeAndName(String code, String name)
			throws Throwable {
		List<CandiateDTO> candiates = new ArrayList<CandiateDTO>();
		List<PBaseVerifyprojectCandiate> list = candiateDaoProxy.getCandiateByCodeAndName(code, name);
		for(PBaseVerifyprojectCandiate pbvc : list){
			CandiateDTO c = new CandiateDTO();
			int PBaseVerifyprojectDepartmentId = pbvc.getPBaseVerifyprojectDepartmentId();
			int PBaseAssistantmaterialDutyId = pbvc.getPBaseAssistantmaterialDutyId();
			int PBaseAssistantmaterialCultureId = pbvc.getPBaseAssistantmaterialCultureId();
			int PBaseAssistantmaterialCandiatecategoryId = pbvc.getPBaseAssistantmaterialCandiatecategoryId();
			int allowanceId = pbvc.getAllowance();
			c.setCandiate(pbvc);
			if(PBaseVerifyprojectDepartmentId != 0){
				PBaseVerifyprojectDepartment department = departmentDaoProxy.getDepartmentById(PBaseVerifyprojectDepartmentId);
				c.setDepartment(department);
			}
			if(PBaseAssistantmaterialDutyId != 0){
				PBaseAssistantmaterialDuty duty = dutyDaoProxy.getDutyById(PBaseAssistantmaterialDutyId);
				c.setDuty(duty);
			}
			if(PBaseAssistantmaterialCultureId != 0){
				PBaseAssistantmaterialCulture culture = cultureDaoProxy.getAssistantmaterialCultureById(PBaseAssistantmaterialCultureId);
				c.setCulture(culture);
			}
			if(PBaseAssistantmaterialCandiatecategoryId != 0){
				PBaseAssistantmaterialCandiatecategory candiateCategory = candiateCategoryDaoProxy.getCandiateCategoryById(PBaseAssistantmaterialCandiatecategoryId);
				c.setCandiateCategory(candiateCategory);
			}
			if(allowanceId != 0){
				PBaseVerifyprojectCandiate allowance = candiateDaoProxy.getCandiateById(allowanceId);
				c.setAllowance(allowance);
			}
			candiates.add(c);
		}
	return candiates;
	}

	@Override
	public List<CandiateDTO> getCandiateByName(String name) throws Throwable {
		List<CandiateDTO> candiates = new ArrayList<CandiateDTO>();
		List<PBaseVerifyprojectCandiate> list = candiateDaoProxy.getCandiateByName(name);
		for(PBaseVerifyprojectCandiate pbvc : list){
			CandiateDTO c = new CandiateDTO();
			int PBaseVerifyprojectDepartmentId = pbvc.getPBaseVerifyprojectDepartmentId();
			int PBaseAssistantmaterialDutyId = pbvc.getPBaseAssistantmaterialDutyId();
			int PBaseAssistantmaterialCultureId = pbvc.getPBaseAssistantmaterialCultureId();
			int PBaseAssistantmaterialCandiatecategoryId = pbvc.getPBaseAssistantmaterialCandiatecategoryId();
			int allowanceId = pbvc.getAllowance();
			c.setCandiate(pbvc);
			if(PBaseVerifyprojectDepartmentId != 0){
				PBaseVerifyprojectDepartment department = departmentDaoProxy.getDepartmentById(PBaseVerifyprojectDepartmentId);
				c.setDepartment(department);
			}
			if(PBaseAssistantmaterialDutyId != 0){
				PBaseAssistantmaterialDuty duty = dutyDaoProxy.getDutyById(PBaseAssistantmaterialDutyId);
				c.setDuty(duty);
			}
			if(PBaseAssistantmaterialCultureId != 0){
				PBaseAssistantmaterialCulture culture = cultureDaoProxy.getAssistantmaterialCultureById(PBaseAssistantmaterialCultureId);
				c.setCulture(culture);
			}
			if(PBaseAssistantmaterialCandiatecategoryId != 0){
				PBaseAssistantmaterialCandiatecategory candiateCategory = candiateCategoryDaoProxy.getCandiateCategoryById(PBaseAssistantmaterialCandiatecategoryId);
				c.setCandiateCategory(candiateCategory);
			}
			if(allowanceId != 0){
				PBaseVerifyprojectCandiate allowance = candiateDaoProxy.getCandiateById(allowanceId);
				c.setAllowance(allowance);
			}
			candiates.add(c);
		}
	return candiates;
	}

}
